package com.itheima.controller;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/users")
    public ModelAndView findUserById(Integer id) {
//        Book book = bookService.findBookById(id);
        System.out.println("11111111111111");
        User user = userService.findUserById(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("users.jsp");
        modelAndView.addObject("user", user);
        return modelAndView;
    }

    @RequestMapping("/list")
    public ModelAndView findAllUser(){
        ModelAndView modelAndView = new ModelAndView();
        List<User> userList = userService.findAllUser();
        System.out.println(userList);
        modelAndView.setViewName("userList.jsp");
        modelAndView.addObject("userList",userList);
        return modelAndView;
    }
}

